package com.gwclh.personnel.controller;


import com.gwclh.personnel.bean.ResultVo;
import com.gwclh.personnel.service.IDeptTransferService;
import com.gwclh.personnel.service.IDismissionService;
import com.gwclh.personnel.service.IEmployeeService;
import com.gwclh.personnel.service.IInternshipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/statistics")
@Api(tags = "各数据统计")
@RestController
public class StatisticsController {

    @Autowired
    IEmployeeService employeeService;

    @Autowired
    IDismissionService dismissionService;

    @Autowired
    IDeptTransferService deptTransferService;

    @Autowired
    IInternshipService internshipService;

    @GetMapping("/home")
    @ApiOperation(value = "统计当前月各数据")
    public ResultVo getHomePageStatistics(){
        Map<String,Object> entryCount = employeeService.statisticsEntryEmpMonth();
        if(entryCount == null){
            entryCount = new HashMap<>();
            entryCount.put("total", 0);
        }
        Map<String,Object> disCount = dismissionService.statisticsDismissionEmpMonth();
        if(disCount == null){
            disCount = new HashMap<>();
            disCount.put("total", 0);
        }
        Map<String,Object> deptTranCount = deptTransferService.statisticsDeptTransferMonth();
        if(deptTranCount == null){
            deptTranCount = new HashMap<>();
            deptTranCount.put("total", 0);
        }
        Map<String,Object> internshipCount = internshipService.statisticsInternshipMonth();
        if(internshipCount == null){
            internshipCount = new HashMap<>();
            internshipCount.put("total",0);
        }

        entryCount.put("title","月入职人数");
        disCount.put("title","月离职人数");
        deptTranCount.put("title","月部门调转数");
        internshipCount.put("title","月转正数人数");

        List<Map<String,Object>> result = new ArrayList<>();
        result.add(entryCount);
        result.add(disCount);
        result.add(deptTranCount);
        result.add(internshipCount);

        return ResultVo.success(result);
    }

    @GetMapping("/deptEmp/{pId}")
    @ApiOperation(value = "统计某公司各部门在岗人数")
    public ResultVo statisticsDeptEmpByCompany(@PathVariable(value = "pId") Integer pId ){
        return employeeService.statisticsDeptEmpByCompany(pId);
    }

    @GetMapping("/station")
    @ApiOperation(value = "统计各岗位在岗人数")
    public ResultVo statisticsStationEmp(){
        return employeeService.statisticsStationEmp();
    }
}
